from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression 
from sklearn import datasets
import matplotlib.pyplot as plt

#导入数据
iris = datasets.load_iris()

#区分数据的自变量和因变量
iris_X = iris.data
print('横坐标（四个自变量）：')
print(iris_X)
iris_Y = iris.target
print('标签：')
print(iris_Y)
#将数据分成训练集和测试集，比例为：80%和20%
iris_train_X , iris_test_X, iris_train_Y ,iris_test_Y = train_test_split(
        iris_X, iris_Y, test_size=0.2,random_state=0)
#训练逻辑回归模型


model = LogisticRegression(solver='lbfgs', max_iter=1000) #此处这个函数中有很多参数可供选择
model.fit(iris_train_X, iris_train_Y)

#预测
print('真值X：')
print(iris_test_X)
print('真值Y：')
print(iris_test_Y)

predict = model.predict(iris_test_X)
print('预测值：')
print(predict)
accuracy = model.score(iris_test_X,iris_test_Y)
print('预测的准确值：')
print(accuracy)





